/**
 * Created by wingsfrog on 2017/6/1.
 */
import {Injectable} from '@angular/core';
import {HttpUtils} from "../utils/http.utils";
import {Observable} from "rxjs/Rx";
import {LocalStorage} from "../app.local-storage";
import {USER} from "./user.service";
import {ParamsModel} from "../model/params.model";

@Injectable()
export class CONTRACT {

  loadContractApi:string='/contract';
  ContractApi:string='/contract/list';
  getBillApi:string='/bill';
  getBillDetailApi:string = '/bill/detail/';
  clacApi: string = '/contract/housePrice';

  constructor(private api:HttpUtils,
              private USER: USER) {

  }
  calc(params: Object, success: any) {
    let pm = new ParamsModel(this.USER)
    pm.url = this.clacApi;
    pm.reqestData = params;
    pm.succCallback = success;
    this.api.get(pm);
  }

  loadContract(params:any=Object,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = this.loadContractApi;
    pm.reqestData = params;
    pm.succCallback = success;
    this.api.post(pm);
  }
  getContractDetail(params:any=Object,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = '/contract/'+params.contractId+'/word';
    pm.succCallback = success;
    this.api.get(pm);
  }
  getContractInfo(params:any=Object,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = '/contract/word';
    pm.reqestData = params;
    pm.succCallback = success;
    this.api.post(pm);
  }
  getContractMsg(id: number,succ){
    let pm = new ParamsModel(this.USER);
    pm.url = `/contract/${id}/detail`;
    pm.succCallback = succ;
    this.api.get(pm)
  }
  getConfirm(params:any,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = '/contract/confirm/'+params.id;
    pm.reqestData = params;
    pm.succCallback = success;
    this.api.put(pm);
  }
  getContractList(success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = this.ContractApi;
    pm.succCallback = success;
    this.api.get(pm);
  }
  getBill(params:any,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = this.getBillApi;
    pm.reqestData = params;
    pm.succCallback = success;
    this.api.get(pm);
  }
  getBillDetail(uuid:string,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = this.getBillDetailApi+uuid;
    pm.succCallback = success;
    this.api.get(pm);
  }
  Checkout(params:any,success:any){
    let pm = new ParamsModel(this.USER);
    pm.url = '/contract/'+params.id+'/operateApply';
    pm.reqestData = params;
    pm.succCallback = success;
    this.api.post(pm);
  }
}
